package com.wyj.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.session.SessionRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
@Slf4j
public class LoginController {

    /**
     * TODO: 登录接口
     *
     * @author wuyijie
     * @date 2021/12/20 5:50 下午
     * @param username
     * @param password
     * @param request
     * @param response
     * @return java.lang.Object
     */
    @GetMapping(value = "/login")
    public Object login(@RequestParam String username, @RequestParam String password, HttpServletRequest request, HttpServletResponse response) {
        if ("admin".equals(username) && "123456".equals(password)) {
            HttpSession session = request.getSession(false);
            if (null == session) {
                session = request.getSession(true);
            }
            String id = session.getId();
            log.info("LoginController sessionid={}", id);
            return id;
        } else {
            return "用户名或者密码不正确";
        }

    }

    /**
     * TODO: 测试接口
     *
     * @author wuyijie
     * @date 2021/12/20 5:50 下午
     * @return java.lang.String
     */
    @GetMapping(value = "/test")
    public String test() {
        return "abcd";
    }
}
